<template>
  <el-dialog
      :model-value="addDialogVisible"
      title="招聘信息添加"
      width="50%"
      draggable
      center
      @close="handleClose"
  >
    <el-form ref="addfrom" :model="form" label-width="100px" :rules="rules">
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="宣传图URL：" prop="img">
            <el-input
                v-model="form.img"
                :rows="2"
                type="textarea"
                placeholder=""
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="驾校背景：" prop="background">
            <el-input
                v-model="form.background"
                :rows="2"
                type="textarea"
                placeholder=""
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="驾校文化：" prop="culture">
            <el-input
                v-model="form.culture"
                :rows="2"
                type="textarea"
                placeholder=""
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="基础设施：" prop="advertisement">
            <el-input
                v-model="form.advertisement"
                :rows="2"
                type="textarea"
                placeholder=""
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleCommit">确认</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { ref} from "vue";
import {ElMessage} from "element-plus";
import {InsertPractise} from "@/api/practise";
import {InsertEvaluation} from "@/api/evaluation";
import {InsertRecruitment} from "@/api/recruitment";
//获取父组件方法或传值
const props = defineProps({
  initGetStudents:{
    type:Function,
    required:true
  }
})
// 获取当前时间
const UpData=()=>{
  const nowDate = new Date();
  const date = {
    year: nowDate.getFullYear(),
    month: nowDate.getMonth() + 1,
    date: nowDate.getDate(),
    hour: nowDate.getHours(),
    min: nowDate.getMinutes(),
    sec:nowDate.getSeconds(),
  }
  const newmonth = date.month>10?date.month:'0'+date.month
  const day = date.date>10?date.date:'0'+date.date
  return  date.year + '-' + newmonth + '-' + day + ' ' + date.hour + ':' + date.min + ':' + date.sec
}
//初始化表单
const form = ref({})

const Emits=defineEmits(['update:modelValue'])

const handleClose=()=>{
  Emits('update:modelValue',false)
}
const addfrom=ref(null)
//添加
const handleCommit= async ()=>{
      await InsertRecruitment(form.value).then(res=>{
        if(res.code===20011){
          ElMessage({
            message: '添加成功',
            type: 'success',
          })
        }else {
          ElMessage({
            message: '添加失败',
            type: 'error',
          })
        }
        props.initGetStudents()
        addfrom.value.resetFields()
      }).catch(err=>{
        ElMessage({
          message: err,
          type: 'error',
        })
        addfrom.value.resetFields()
      })
  handleClose()
}
</script>

<style scoped>

</style>